﻿/*============================================
 * 类名 :InterpretCommand
 * 描述 :
 *   
 * 创建时间: 2011-2-2 11:32:10
 * Blog:   http://home.cnblogs.com/xiangism
 *============================================*/
using System;
using System.Collections.Generic;

using System.Text;
using MathAssistLibrary;

namespace MathAssist
{
    /// <summary>对命令进行解释</summary>
    class InterpretCommand
    {
        /// <summary>所有的命令</summary>
        public List<ICommand> Commands { get; set; }

        public InterpretCommand(List<ICommand> cmds) {
            this.Commands = cmds;
        }
        /// <summary>对命令进行解释执行</summary>  
        public string Interpret(string command) {
            string name = "";
            string parameter = "";
            if (command.IndexOf(" ") == -1) {
                name = command;
            } else {
                name = command.Substring(0, command.IndexOf(" "));
                parameter = command.Substring(command.IndexOf(" "));
            }

            foreach (ICommand i in Commands) {
                if (i.Name == name) {
                    return i.Excute(parameter);
                }
            }
            return "未知的命令";
        } // end function Interpret

    }
}
